/*
 * TileGroup.java
 *
 *  Copyright (c) 2008 Corey Oliver and Anshul Kumaria
 *
 *  This file is part of Balls of Fury.
 *
 *  Balls of Fury is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Balls of Fury is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 *
 */

/*
 * EDIT:  03/13/2008 - This is an example of how an edit performed to the class 
 * would appear.
 */

package ballsoffury.playground.model;

/**
 * <code>TileGroup</code> allows for management of the game. Various methods 
 * are included in this class to show various screens, alter preferences,  
 * and exit the application.
 *
 * @author Corey Oliver
 * @version $Revision:$ $Date:$
 */
public abstract class TileGroup {

	Tile tiles[] = new Tile[] { null, null, null, null };
	protected int refCount = 0;

	public TileGroup() {
		super();
	}

	protected boolean assignTo(Tile tile) {
		tile.setGroup( this );
		tiles[refCount] = tile;
		refCount++;
		return refCount < 4;
	}

	protected void remove(Tile tile) {
		for( int i=0; i<4; ++i )
		{
			if( tiles[i] == tile )
				tiles[i] = null;
		}
	}

	public Hint getHint() {
		Tile first = null;
		Tile second = null;
		for (int i = 0; i < 4; ++i) {
			if (tiles[i] != null) {
				if (first == null)
					first = tiles[i];
				else {
					second = tiles[i];
					break;
				}
			}
		}
	
		if (first != null && second != null)
		{
			if( !first.isBlocked() && !second.isBlocked() )
				return new Hint(first, second);
		}
			
		return null;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		return false;
	}

	 
	public abstract String getTextureResource( Tile tile );

	public Tile[] getTiles() {
		return tiles;
	} 
}